#pragma once
#ifndef NULL
#define NULL 0
#endif

#include "templatevector.h"

template < class TYPE >
class Asset {
private:
	char * FileName;
	TYPE Data;
public:
	Asset () : FileName(NULL), Data(NULL) {}
	Asset ( char * a_FileName , TYPE a_Data ) {
		FileName = a_FileName;
		Data = a_Data;
	}
	const char * GetFileName() const {return FileName;}
	const TYPE GetData() const {return Data;}
	bool operator==(Asset<TYPE> A){
		if( FileName == A.FileName && Data == A.Data )
			return true;
		return false;
	}
};

template < class TYPE >
class Library {
private:
	TemplateVector<Asset<TYPE>> * Media;
public:

	Library() {
		Media = new TemplateVector<Asset<TYPE>>;
	}
	~Library() {
		//Media->Clear();
		delete Media;
	}


	/**
	  *Returns the index of the asset in the library
	  *Does not add the file if it already exists in the library
	  */
	const int AddAsset(Asset<TYPE> a_Asset) {
		int index = IndexofAsset( a_Asset );
		if( index == -1 ) {
			Media->add( a_Asset );
			return Media->indexOf( a_Asset );
		}
		else return index;
	}

	/**
	  *Returns the vector size
	  */
	const int GetSize() { return Media->getSize(); }

	TYPE FindByFileName(char * File) {
		Asset<TYPE> A;
		for(int i = 0;i < Media->size();i++) {
			if(File == Media->get(i).GetFileName()){
				return Media->get(i).GetData();
			}
		}
		return A.GetData();
	}
	/**
	  *Basic Removal
	  */
	void RemoveAsset(Asset<TYPE> a_Asset) {
		Media->removeData( a_Asset );
	}
	void RemovebyIndex(int a_Index) {
		Media->remove(a_Index);
	}
	void RemovebyFile(char * FileName) {
		for(int i = 0;i < Media->size();i++) {
			if(FileName == Media->get(i).GetFileName()){
				Media->remove(i);
				break;
			}
		}
	}

	/**
	  *Basic Get
	  */
	Asset<TYPE> GetAsset(int const & i) {
		return Media->get(i);
	}
	TYPE GetAssetData(int const & i) {
		return ((Asset<TYPE>)Media->get(i)).GetData();
	}

	/**
	  *Basic Find Index
	  */
	const int IndexofAsset(Asset<TYPE> const & a_Asset) const {
		for(int i = 0;i < Media->size();i++) {
			if( a_Asset.GetFileName() == Media->get(i).GetFileName() )
				return i;
		}
		return -1;
	}
};